<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="./imgs/favicon.png" type="image/x-icon">
    <link rel="preload" href="./css/common.css" as="style">
    <link rel="preload" href="./js/vue.js" as="script">
    <link rel="preload" href="./components/header.js" as="script">
    <link rel="preload" href="./components/nav.js" as="script">
    <link rel="preload" href="./components/newsBox.js" as="script">
    <link rel="stylesheet" href="./css/common.css">
    <link rel="stylesheet" href="./css/search.css">
    <script async="async" src="https://www.google.com/adsense/search/ads.js"></script>
    <title>Funny Money</title>
    <script type="text/javascript" charset="utf-8">
        (function (g, o) {
            g[o] = g[o] || function () {
                (g[o]['q'] = g[o]['q'] || []).push(
                    arguments)
            }, g[o]['t'] = 1 * new Date
        })(window, '_googCsa');
    </script>
</head>
<body>
    <div id="app" v-cloak>

        <popup v-model="showSide">
            <side-nav></side-nav>
        </popup>

        <div class="container">

            <side-header @menu-click="handleOpenSideBar">
                <side-nav></side-nav>
            </side-header>

            <div class="container-main">
                <div class="main">
                    <div class="search">
                        <div class="search-title">
                            <h1 class="search-title_h1">
                                Search results for: “{{keywords}}”
                            </h1>
                        </div>
                        <div class="search-main">
                            <input class="search-main_input" type="text" v-model="searchPageWords" @keyup.enter="handleToSearch">
                            <button class="search-main-button" @click="handleToSearch">
                                <svg class="search-icon" viewBox="0 0 24 24" width="24" height="24" fill="#ffffff">
                                    <path d="M13 5c-3.3 0-6 2.7-6 6 0 1.4.5 2.7 1.3 3.7l-3.8 3.8 1.1 1.1 3.8-3.8c1 .8 2.3 1.3 3.7 1.3 3.3 0 6-2.7 6-6S16.3 5 13 5zm0 10.5c-2.5 0-4.5-2-4.5-4.5s2-4.5 4.5-4.5 4.5 2 4.5 4.5-2 4.5-4.5 4.5z"></path>
                                </svg>
                            </button>
                        </div>
                    </div>
                    <div id="afscontainer1"></div>
                    <news-box type="simple" v-for="item in list" :key="item.id" :options="item"></news-box>
                    <news-box type="simple" v-for="item in mock" :key="item.id" :options="item"></news-box>
                </div>

                <!-- <aside class="aside"></aside> -->
            </div>

        </div>

        <side-footer v-if="!loading"></side-footer>

        <cookies></cookies>

    </div>
</body>
<script src="./main.js"></script>
<script src="./mixins/index.js"></script>
<script src="./components/header.js"></script>
<script src="./components/footer.js"></script>
<script src="./components/popup.js"></script>
<script src="./components/nav.js"></script>

<script src="./components/newsBox.js"></script>
<script src="./components/cookies.js"></script>
<script src="./mock.js"></script>
<script src="./js/vue.js"></script>
<script>
    var vm = new Vue({
        el: '#app',
        mixins: [mixin],
        components: {
            SideHeader: header,
            SideFooter: footer,
            SideNav: nav,
            Popup: popup,
            newsBox: news,
            cookies: cookies
        },
        data() {
            return {
                list: [],
                keywords: '',
                searchPageWords: '',
                mock
            }
        },
        created() {
            this.searchPageWords = this.keywords = this.getQueryString('keywords') ? this.getQueryString('keywords') : ''
            this.handleFetchSearchResult()
            document.title = this.searchPageWords
        },
        methods: {
            getQueryString(name) {
                var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
                var r = window.location.search.substr(1).match(reg);

                if (r != null) {
                    var result = r[2];
                    result = result.replace(/\+/g, ' ');
                    return decodeURIComponent(result);
                }
                return null;
            },
            loadAfs() {
                var pageOptions = {
                    // "adtest": "on",
                    "adPage": 1,
                    "pubId": "pub-8180331903483073",
                    "channel": "3977029528",
                    "styleId": "6973188265",
                    "query": this.keywords,
                    "adsafe": "low",
                    // "resultsPageBaseUrl": "https://search.funnytest.top/search/" + url_parameter,
                    "resultsPageBaseUrl": "https://www.thefunnymoney.com/search.html?",
                    // Enter the base url for your results page
                    "resultsPageQueryParam": "keywords"// (Default to "q") Matches the param denoting the query on the search page
                };
                var adblock1 = {
                    "container": "afscontainer1",
                    "maxTop": "2"
                };
                // var adblock2 = {
                //     "container": "afscontainer2",
                //     "number": "4"
                // };
                // var rsblock1 = {
                //     "container": "relatedsearches1",
                //     "relatedSearches": 6
                // };
                _googCsa('ads', pageOptions, adblock1);
            },
            handleToSearch() {
                this.keywords = this.searchPageWords
                window.location.href = `./search.html?keywords=${this.keywords}`
            },
            handleFetchSearchResult() {
                fetch('https://migame.vip/gamefront/blog/searchForBlog', {
                    headers: {
                        'Content-Type': 'application/json; charset=utf-8'
                    },
                    method: 'post',
                    body: JSON.stringify({
                        keyWord: this.keywords
                    })
                })
                    .then(res => res.json())
                    .then(res => {
                        if (res.code == 0) {
                            this.list = res.data
                        }
                        this.$nextTick(this.loadAfs)
                    })
                    .catch(err => {
                        throw new Error(err)
                    })
            },
            fetchCategories() {
                fetch('https://migame.vip/gamefront/blog/blogTypeApiList', {
                    headers: {
                        'Content-Type': 'application/json; charset=utf-8'
                    },
                    method: 'post',
                    body: JSON.stringify({
                        pageNum: 1,
                        pageSize: 20
                    })
                })
                    .then(res => res.json())
                    .then(res => {
                        if (res.code == 0) {
                            // this.fetchCategoriesData = res.data
                        }
                    })
                    .catch(err => {
                        throw new Error(err)
                    })
            }
        }
    })
</script>

</html>